#!/bin/bash
#---------------
# Testing frr
#---------------
set -e

# modify config file to enable all daemons and copy config files
CONFIG_FILE=/etc/frr/daemons
DAEMONS=("zebra" "bgpd" "ospfd" "ospf6d" "ripd" "ripngd" "isisd" "pimd")

for daemon in "${DAEMONS[@]}"
do
    sed -i -e "s/${daemon}=no/${daemon}=yes/g" $CONFIG_FILE
    cp /usr/share/doc/frr/examples/${daemon}.conf.sample /etc/frr/${daemon}.conf
done

# reload frr
/etc/init.d/frr restart > /dev/null 2>&1

# check daemons
for daemon in "${DAEMONS[@]}"
do
    echo -n "check $daemon  -  "
    if pidof -x $daemon > /dev/null; then
        echo "${daemon} OK"
    else
        echo "ERROR: ${daemon} IS NOT RUNNING"
        exit 1
    fi
done
